package com.xpjhs.user.web.controller;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;






import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xpjhs.common.util.UserSessionManager;
import com.xpjhs.user.model.User;
import com.xpjhs.user.service.UserService;

/*
 * @author chen
 * 
 * create at 2014-9-10 17:47
 */
@Controller
@RequestMapping("/user")
public class UserFormController {
	@Autowired
	private UserService userService;
	
	
    //用户保存
	@RequestMapping(value = "/save", method = RequestMethod.GET)
	public String save(User user) throws FileNotFoundException, IOException {
		userService.save(user);
		System.out.println(user.toString());
		return "login/login";
	}
	
	//个人信息修改
	@RequestMapping("/update")
	public String update(
			@RequestParam(value="password",required=false) String password,
			User user,
			HttpServletRequest request,
			@RequestParam(value="repsw",required=false) String repsw)
	{
		User u=UserSessionManager.getUserFromSession(request);
		u.setQqName(user.getQqName());	
		u.setContent(user.getContent());
		u.setEmail(user.getEmail());
		u.setPhone(user.getPhone());
		u.setSex(user.getSex());
		if(!password.equals("")&&password!=null)
			if(password.equals(repsw))
				u.setPassword(password);
		userService.save(u);
		return "redirect:/index";
	}
}
